<script>
    
    $(document).ready(function(){
        
        $('#paises').change(function(){
            $('#regiones').load("/stores/getRegionesPorPais", {
                pais: $("#paises").val()
            });
            $('#provincias').html('');
            $('#comunas').html('');
            
        });
        
        $('#regiones').change(function(){
            $('#provincias').load("/stores/getProvinciasPorRegiones", {
                region: $("#regiones").val()
            });
            $('#comunas').html('');
            
        });
        
        
        $('#provincias').change(function(){
            $('#comunas').load("/stores/getComunasPorProvincias", {
                provincia: $("#provincias").val()
            });
            
        });
        
        
        
        
    });
    
    
</script>

<script src="/js/plugins/validation/jquery.validate.min.js"></script>
<script src="/js/plugins/validation/additional-methods.min.js"></script>
<div class="row-fluid">


    <div class="span12">
        <div class="box box-bordered box-color">
            <div class="box-title">
                <h3><i class="icon-th-list"></i> Editar Local</h3>
            </div>
            <div class="box-content nopadding">
                <form action="<?php echo url_for('adminstores/updateStore'); ?>" method="POST" class='form-horizontal form-bordered form-validate' id="store">
                    <input type="hidden" name="store[id]" value="<?php echo $store[0]['id_store']; ?>" />


                    <div class="control-group">
                        <label for="nombres" class="control-label">Nombres</label>
                        <div class="controls">
                            <input type="text" name="store[name]" id="nombres" value="<?php echo $store[0]['name']; ?>" placeholder="Nombres" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="address" class="control-label">Dirección</label>
                        <div class="controls">
                            <input type="text" name="store[address]" id="address" value="<?php echo $store[0]['address']; ?>" placeholder="Dirección" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar la Dirección" data-rule-minlength="3" data-msg-minlength="La Dirección debe ser Mayor a 2 caracteres">
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="paises" class="control-label">Pais</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[paises]" id="paises" data-rule-required="true" data-msg-required="Debe Seleccionar País">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($paises as $value) { ?>
                                        <option value="<?php echo $value['id_pais']; ?>"  <?php echo (($store[0]['id_pais'] == $value['id_pais']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="regiones" class="control-label">Regiones</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[regiones]" id="regiones" data-rule-required="true" data-msg-required="Debe Seleccionar Región">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($regiones as $value) { ?>
                                        <option value="<?php echo $value['id_region']; ?>"  <?php echo (($store[0]['id_region'] == $value['id_region']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="provincias" class="control-label">Provincia</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[provincias]" id="provincias" data-rule-required="true" data-msg-required="Debe Seleccionar Provincia">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($provincias as $value) { ?>
                                        <option value="<?php echo $value['id_provincia']; ?>"  <?php echo (($store[0]['id_provincia'] == $value['id_provincia']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="comunas" class="control-label">Comuna</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[comunas]" id="comunas" data-rule-required="true" data-msg-required="Debe Seleccionar Comuna">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($comunas as $value) { ?>
                                        <option value="<?php echo $value['id_comuna']; ?>"  <?php echo (($store[0]['id_comuna'] == $value['id_comuna']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="channels" class="control-label">Canal</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[channels]" id="channels" data-rule-required="true" data-msg-required="Debe Seleccionar Canal">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($channels as $value) { ?>
                                        <option value="<?php echo $value['id_channel']; ?>"  <?php echo (($store[0]['id_channel'] == $value['id_channel']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="customers" class="control-label">Cliente</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[customers]" id="customers" data-rule-required="true" data-msg-required="Debe Seleccionar Cliente">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($customers as $value) { ?>
                                        <option value="<?php echo $value['id_customer']; ?>"  <?php echo (($store[0]['id_customer'] == $value['id_customer']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="formats" class="control-label">Formato</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[formats]" id="formats" data-rule-required="true" data-msg-required="Debe Seleccionar Formato">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($formats as $value) { ?>
                                        <option value="<?php echo $value['id_format']; ?>"  <?php echo (($store[0]['id_format'] == $value['id_format']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="codeFormats" class="control-label">Código Formato</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[codeFormats]" id="codeFormats" data-rule-required="true" data-msg-required="Debe Seleccionar Código Formato">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($codeFormats as $value) { ?>
                                        <option value="<?php echo $value['id_codeformat']; ?>"  <?php echo (($store[0]['id_codeformat'] == $value['id_codeformat']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="concessions" class="control-label">Concessiones</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[concessions]" id="concessions" data-rule-required="true" data-msg-required="Debe Seleccionar Concessions">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($concessions as $value) { ?>
                                        <option value="<?php echo $value['id_concession']; ?>"  <?php echo (($store[0]['id_concession'] == $value['id_concession']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="locations" class="control-label">Ubicación</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[locations]" id="locations" data-rule-required="true" data-msg-required="Debe Seleccionar Ubicación">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($locations as $value) { ?>
                                        <option value="<?php echo $value['id_location']; ?>"  <?php echo (($store[0]['id_location'] == $value['id_location']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>



                    <div class="control-group">
                        <label for="clusters" class="control-label">Cluster</label>
                        <div class="controls">
                            <div class="input-large">
                                <select name="store[clusters]" id="clusters" data-rule-required="true" data-msg-required="Debe Seleccionar Cluster">
                                    <option value="">-- Seleccione --</option>
                                    <?php foreach ($clusters as $value) { ?>
                                        <option value="<?php echo $value['id_cluster']; ?>"  <?php echo (($store[0]['id_cluster'] == $value['id_cluster']) ? 'selected' : ''); ?>><?php echo $value['name']; ?></option>
                                    <?php }
                                    ?>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="control-group">
                        <label for="code_supplier" class="control-label">Código Proveedor</label>
                        <div class="controls">
                            <input type="text" name="store[code_supplier]" id="code_supplier" value="<?php echo $store[0]['code_supplier']; ?>" placeholder="Código Proveedor" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Código Proveedor" data-rule-minlength="3" data-msg-minlength="El Código Proveedor debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="surface" class="control-label">Superficie</label>
                        <div class="controls">
                            <input type="text" name="store[surface]" id="surface" value="<?php echo $store[0]['surface']; ?>" placeholder="Superficie" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar ls Superficie">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="responsiblea" class="control-label">Responsable 1</label>
                        <div class="controls">
                            <input type="text" name="store[responsiblea]" id="responsiblea" value="<?php echo $store[0]['responsiblea']; ?>" placeholder="Responsable 1" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="responsibleb" class="control-label">Responsable 2</label>
                        <div class="controls">
                            <input type="text" name="store[responsibleb]" id="responsibleb" value="<?php echo $store[0]['responsibleb']; ?>" placeholder="Responsable 2" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="responsiblec" class="control-label">Responsable 3</label>
                        <div class="controls">
                            <input type="text" name="store[responsiblec]" id="responsiblec" value="<?php echo $store[0]['responsiblec']; ?>" placeholder="Responsable 3" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="manager" class="control-label">Gerente</label>
                        <div class="controls">
                            <input type="text" name="store[manager]" id="manager" value="<?php echo $store[0]['manager']; ?>" placeholder="Gerente" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="administrator" class="control-label">Administrador</label>
                        <div class="controls">
                            <input type="text" name="store[administrator]" id="administrator" value="<?php echo $store[0]['administrator']; ?>" placeholder="Administrador" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre" data-rule-minlength="3" data-msg-minlength="El Nombre debe ser Mayor a 2 caracteres">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="average" class="control-label">Promedio Venta</label>
                        <div class="controls">
                            <input type="text" name="store[average]" id="average" value="<?php echo $store[0]['average_sales']; ?>" placeholder="Promedio Venta" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar el Nombre">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="latitude" class="control-label">Latitud</label>
                        <div class="controls">
                            <input type="text" name="store[latitude]" id="latitude" value="<?php echo $store[0]['latitude']; ?>" placeholder="Latitud" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar la Latitud" >
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="longitude" class="control-label">Longitud</label>
                        <div class="controls">
                            <input type="text" name="store[longitude]" id="longitude" value="<?php echo $store[0]['longitude']; ?>" placeholder="Longitud" class="input-xlarge" data-rule-required="true" data-msg-required="Debe Ingresar la Longitud">
                        </div>
                    </div>


                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">Guardar</button>
                        <button type="button" class="btn">Cancelar</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>